package com.chb.demo.service;

import com.chb.demo.dao.AdminDao;
import com.chb.demo.dao.CompanyDao;
import com.chb.demo.dao.UserDao;
import com.chb.demo.entity.Admin;
import com.chb.demo.entity.Company;
import com.chb.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class LoginService {
    @Autowired
    public AdminDao adminDao;
    @Autowired
    public CompanyDao companyDao;
    @Autowired
    public UserDao userDao;

    public Map<String, Object> loginValid(String account, String password){
        Map<String, Object> map = new HashMap<>();
        map.put("msg","请求成功");
        map.put("success",true);

        Admin admin = adminDao.loginCheck(account,password);
        Company company = companyDao.loginCheck(account,password);
        User user = userDao.loginCheck(account,password);
        if (admin!=null){
            map.put("ROLE","Admin");
            map.put("INFO",admin);

        }
        else if (company!=null){
            map.put("ROLE","Company");
            map.put("INFO",company);
        }
        else if (user!=null){
            map.put("ROLE","User");
            map.put("INFO",user);
        }
        else{
            map.put("msg","用户名或密码错误");
            map.put("success",false);
        }

        return map;

    }
}
